﻿using System.Linq;
using NUnit.Framework;
using StreetPacMan.Server.Facade;

namespace StreetPacMan.Server.Tests.Integ
{
    [TestFixture]
    public class GameStateApplesVsPollServerRemovedApples : BaseCleaner
    {
        [Test]
        public void Poll()
        {
            var instance = ServerFacadeFactory.GetServerFacade();
            instance.CreateGameX("GameName");
            instance.CreateGameX("GameName2");
            var pacman1 = instance.JoinGameX("GameName", "PacManName", PlayerRole.PacMan);
            var pacman2 = instance.JoinGameX("GameName2", "PacManName", PlayerRole.PacMan);

            var state1 = instance.GetGameState(new GetGameStateParameters(pacman1.PlayerId));
            var state2 = instance.GetGameState(new GetGameStateParameters(pacman2.PlayerId));
            var pollResults1 = instance.UpdateMyWhereabouts(new ServerPollParameters(pacman1.PlayerId, state1.Apples.First().Lat, state1.Apples.First().Lng, true));
            var pollResults2 = instance.UpdateMyWhereabouts(new ServerPollParameters(pacman2.PlayerId, state2.Apples.First().Lat, state2.Apples.First().Lng, true));

            Assert.IsTrue(pollResults1.RemovedAppleIds.All(x => state1.Apples.Select(y => y.EntityId).Contains(x)));
            Assert.IsTrue(pollResults2.RemovedAppleIds.All(x => state2.Apples.Select(y => y.EntityId).Contains(x)));
        }
    }
}